package org.sport.presenter;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.sport.logic.Logic_LinkPeople;
import org.sport.model.jsonModel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

/**
 * Created by zehong
 *
 * 主要用于对接联系人的接口
 *
 * 包括展示我的联系人，我的群组及创建群组，新朋友的请求及处理，搜索添加新朋友？搜索添加新群组？
 */

@Controller
public class Interface_LinkPeople {

    @Autowired
    Logic_LinkPeople logicForlink;




    /**
     * 功能：主界面，一进去就要展示我的联系人列表，以及未读消息数量
     * json参数：用户手机号码
     * 返回：用户所有联系人信息及未读消息数量
     */
    @RequestMapping(value = "/4/home", method = RequestMethod.POST)
    public void home(@RequestBody Json_4_home json_4_home
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface-link-home");
        ArrayList<Json_4_home> all=logicForlink.home(json_4_home);
        try {

            response.getWriter().print(JSONArray.fromObject(all).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }




    /**
     * 功能：新的朋友，进入新的朋友请求的页面,在这里可以看到其他人的请求信息
     * json参数：用户手机号码
     * 返回：用户收到的所有好友申请信息
     */
    @RequestMapping(value = "/4/newFriend_list", method = RequestMethod.POST)
    public void newFriend_list(@RequestBody Json_4_newFriend_list json_4_newFriend_list
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface-link-newFriend_list");
        ArrayList<Json_4_newFriend_list> all=logicForlink.newFriend_list(json_4_newFriend_list);
        try {

            response.getWriter().print(JSONArray.fromObject(all).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }




    /**
     * 功能：新的朋友，进入新的朋友请求的页面,可以处理请求信息，接收或者拒绝他人的请求
     * json参数：用户手机号码以及想要处理的陌生人的电话号码，接受或者拒绝
     * 返回：处理结果
     */
    @RequestMapping(value = "/4/newFriend_handle", method = RequestMethod.POST)
    public void newFriend_handle(@RequestBody Json_4_newFriend_handle json_4_newFriend_handle
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface-link-newFriend_handle");
        Json_4_newFriend_handle one=logicForlink.newFriend_handle(json_4_newFriend_handle);
        try {

            response.getWriter().print(JSONObject.fromObject(one).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }





    /**
     * 功能：群组，进入群组页面，可以看到有关于我的所有群组
     * json参数：用户手机号码
     * 返回：用户所有群组信息
     */
    @RequestMapping(value = "/4/group", method = RequestMethod.POST)
    public void group(@RequestBody Json_4_group json_4_group
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface-link-group");
        ArrayList<Json_4_group> all=logicForlink.group(json_4_group);
        try {

            response.getWriter().print(JSONArray.fromObject(all).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }






    /**
     * 功能：点击新增群组按钮，添加新的群组
     * json参数：用户手机号码及要新建的群组的各种信息
     * 返回：创建群组结果
     */
    @RequestMapping(value = "/4/creategroup", method = RequestMethod.POST)
    public void creategroup(@RequestBody Json_4_creategroup json_4_creategroup
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface-link-creategroup");
        Json_4_creategroup one=logicForlink.creategroup(json_4_creategroup);
        try {

            response.getWriter().print(JSONObject.fromObject(one).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }





    /**
     * 功能：在搜索栏通过用户电话号码搜索陌生人，可以找到对应的陌生人
     * json参数：用户手机号码，要找的用户手机号码
     * 返回：要找的用户的所有信息
     */
    @RequestMapping(value = "/4/add_findpeople", method = RequestMethod.POST)
    public void add_findpeople(@RequestBody Json_4_add_findpeople json_4_add_findpeople
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface-link-add_findpeople");
        Json_4_add_findpeople one=logicForlink.add_findpeople(json_4_add_findpeople);
        try {

            response.getWriter().print(JSONObject.fromObject(one).toString());
        } catch (IOException e) {
            e.printStackTrace();

        }
    }





    /**
     * 功能：在搜索栏通过群组名字找讨论群，可以找到几个同样名字的群
     * json参数：用户手机号码，要找的群的名字
     * 返回：一群相同名字的群的列表
     */
    @RequestMapping(value = "/4/add_findgroup", method = RequestMethod.POST)
    public void add_findgroup(@RequestBody Json_4_add_findgroup json_4_add_findgroup
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface-link-add_findgroup");
        ArrayList<Json_4_add_findgroup> all=logicForlink.add_findgroup(json_4_add_findgroup);
        try {

            response.getWriter().print(JSONArray.fromObject(all).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }






    /**
     * 功能：在搜索栏通过电话找到人之后，点击添加，发送添加请求
     * json参数：用户手机号码，要添加的用户的手机号码
     * 返回：申请发送结果
     */
    @RequestMapping(value = "/4/add_addpeople", method = RequestMethod.POST)
    public void add_addpeople(@RequestBody Json_4_add_addpeople json_4_add_addpeople
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface-link-add_addpeople");
        Json_4_add_addpeople one=logicForlink.add_addpeople(json_4_add_addpeople);
        try {

            response.getWriter().print(JSONObject.fromObject(one).toString());
        } catch (IOException e) {
            e.printStackTrace();

        }
    }






    /**
     * 功能：在搜索栏通过群组名字找到群后，点击添加，发送添加请求
     * json参数：用户手机号码，要添加的群组ID
     * 返回：申请发送结果
     */
    @RequestMapping(value = "/4/add_addgroup", method = RequestMethod.POST)
    public void add_addgroup(@RequestBody Json_4_add_addgroup json_4_add_addgroup
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface-link-add_addgroup");
        Json_4_add_addgroup one=logicForlink.add_addgroup(json_4_add_addgroup);
        try {

            response.getWriter().print(JSONObject.fromObject(one).toString());
        } catch (IOException e) {
            e.printStackTrace();

        }
    }



}
